#include <iostream>
#include "common/Cmd.h"
#include "cmdline.h"
#include "classpath/Classpath.h"

using namespace std;
using namespace cmdline;

Cmd parseCmd(int argc, char **argv);
void startJVM(const Cmd &cmd);

int main(int argc, char *argv[]) {
    Cmd cmd = parseCmd(argc, argv);

    if (cmd.versionFlag) {
        cout << "Java Kan version 1.0.0" << endl;
    } else if (cmd.helpFlag) {
        cout << "Usage: java -cp [classpath] [class]" << endl;
    } else {
        startJVM(cmd);
    }
    return 0;
}

void startJVM(const Cmd &cmd) {
    Classpath* cp = parse(cmd.xJreOption, cmd.cpOption);
}

Cmd parseCmd(int argc, char **argv) {
    Cmd cmd = *new Cmd();

    parser p;
    p.add<string>("cp", 'c', "Host Name", false, "");
    p.add<string>("Xjre", '\0', "Jre Options", false, "");
    p.add("version", 'v', "Version");
    p.add("help", 'h', "Help?");
    p.parse_check(argc, argv);

    if (p.exist("version")) {
        cmd.versionFlag = true;
    }

    if (p.exist("help")) {
        cmd.helpFlag = true;
    }

    cmd.cpOption = p.get<string>("cp");
    cmd.xJreOption = p.get<string>("Xjre");

    return cmd;
}